<template>
	<view>
		<!-- <u-search placeholder="请输入关键字" v-model="keyword"></u-search> -->
		<u-button type="primary"  text="提出整改" @click="add" v-if="(user.Roles.indexOf('项目经理')>-1 || user.Roles.indexOf('管理员')>-1)"></u-button>
		<u-sticky>
			<u-subsection :list="lt" :current="current"  @change="sectionChange"></u-subsection>
		</u-sticky>
		
<!-- 		<u-search
			v-model="keyword"
			:show-action="false"
			@change="searchlist"
			placeholder="请输入关键字"
		></u-search> -->
		<u-list @scrolltolower="scrolltolower">
			<u-list-item v-for="(item, index) in list" :key="index">
				<u-cell :title="'工程:'+item.BuildInfo.Name" :label="'提出人：'+item.UserName+'  '+item.CreateTime" isLink @click="openpage" :name="item.Id" icon="https://cdn.uviewui.com/uview/example/tag.png">
				</u-cell>
			</u-list-item>
			<u-loadmore :status="status" v-if="loading"/>
		</u-list>
	</view>
</template>

<script>
	import {
		getbuildputrightlist
	} from '@/common/api.js'
	export default {
		data() {
			return {
				current:0,
				lt: ['未完成','已完成'],
				user: JSON.parse(uni.getStorageSync("$userinfo")),
				list: [],
				keyword: "",
				pageIndex:1, //当前页数
				pageSize:20, //页数大小
				totalPage: "",//总页数
				total: 0, //数据总数
				status: 'loadmore', //加载状态
				loading: true
			}
		},
		onLoad()
		{
			
		},
		onShow()
		{
			this.list=[]
			this.getlist()
		},
		methods: {
			sectionChange(index)
			{
				this.current=index
				this.pageIndex=1
				this.list=[]
				this.getlist();
			},
			openpage(e)
			{ 
				uni.navigateTo({
					url: "view?id="+e.name
				})
			},
			async getlist() {
				// let querytype = this.$route.query.querytype
				let para = {
					Parameters:[],
				}
		// 		if (this.keyword != "") {
		// 			para.Parameters.push({
		// 				FieldName: "Name",
		// 				ConditionalType: "Like",
		// 				FieldValue: this.keyword
		// 			})
		
		// 		}
				// para.Parameters.push({
				// 	FieldName: "Status",
				// 	ConditionalType: "Equal",
				// 	FieldValue: "已派工",
				// })
				para.Parameters.push({
					FieldName: "Status",
					ConditionalType: "Equal",
					FieldValue: this.lt[this.current],
				})
				para.OrderBys = ['CreateTime desc']
				para.pageSize = this.pageSize
				para.pageIndex = this.pageIndex
				// if (querytype == "日志") {


				// }
				await getbuildputrightlist(para).then(res => {
					let data = res.data
					this.list.push(...data)
					this.total = res.count
					this.totalPage = Math.ceil(this.total / this.pageSize)
				})
			},
			scrolltolower(){
				// 如果当前页数大于等于总页数，状态修改为没有更多了，不再继续往下执行代码
				if(this.pageIndex >= this.totalPage) {
					this.status = 'nomore';
						return;
					} ;
				this.status = 'loading';//状态改为加载中
				this.pageIndex = ++ this.pageIndex;//页面新增一页
				this.getlist();//修改页数后，重新获取数据
			},
			async searchlist(){
				this.buildlist = [] //初始化
				this.pageIndex = 1 //初始化当前页数为1
				this.loading = true
				await this.getlist()
				if(this.buildlist.length < this.pageSize){
					this.loading = false; //如果数据列表小于当前页数，就让加载标签消失
				}
			},
			add()
			{
				uni.navigateTo({
					url:"buildlist"
				})
			}
		},
		}
</script>

<style>

</style>
